﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random();
            string[,] board2 = new string [8,7];
            int[,] board = new int [8,7]; //([8,7])

            //direction fill
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    board2[i, j] = i + "," + j;
                }
            }

            //direction print
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    Console.Write(board2[i, j] + " | ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();


            //random fill
            for(int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    board[i, j] = random.Next(2);
                }
            }

            //random print
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    Console.Write(board[i, j] + " | ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            //Console.ReadLine();

            //win check
            int xMax = 8;
            int yMax = 7;
            List<string> oMatchList = new List<string>();
            List<string> xMatchList = new List<string>();
            
            //right
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (j + 3 > (yMax - 1)) {}//do nothing
                    else
                    {
                        if (board[i, j] == 0 && board[i, (j + 1)] == 0 && board[i, (j + 2)] == 0 && board[i, (j + 3)] == 0)
                        {
                            oMatchList.Add("Right at (" + i + "," + j + ")");
                        }
                        else if (board[i, j] == 1 && board[i, (j + 1)] == 1 && board[i, (j + 2)] == 1 && board[i, (j + 3)] == 1)
                        {
                            xMatchList.Add("Right at (" + i + "," + j + ")");
                        }
                    }
                }
            }

            //left
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (j - 3 < 0) {}//do nothing
                    else
                    {
                        if (board[i, j] == 0 && board[i, (j - 1)] == 0 && board[i, (j - 2)] == 0 && board[i, (j - 3)] == 0)
                        {
                            oMatchList.Add("Left at (" + i + "," + j + ")");
                        }
                        else if (board[i, j] == 1 && board[i, (j - 1)] == 1 && board[i, (j - 2)] == 1 && board[i, (j - 3)] == 1)
                        {
                            xMatchList.Add("Left at (" + i + "," + j + ")");
                        }
                    }
                }
            }

            //down (would be up)
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (i +3 > (xMax - 1)) { }//do nothing
                    else
                    {
                        if (board[i, j] == 0 && board[(i + 1), j] == 0 && board[(i + 2), j] == 0 && board[(i +3), j] == 0)
                        {
                            oMatchList.Add("Downward at (" + i + "," + j + ")");
                        }
                        else if (board[i, j] == 1 && board[(i + 1), j] == 1 && board[(i + 2), j] == 1 && board[(i + 3), j] == 1)
                        {
                            xMatchList.Add("Downward at (" + i + "," + j + ")");
                        }
                    }
                }
            }

            //up (would be down)
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (i - 3 < 0) { }//do nothing
                    else
                    {
                        if (board[i, j] == 0 && board[(i - 1), j] == 0 && board[(i - 2), j] == 0 && board[(i - 3), j] == 0)
                        {
                            oMatchList.Add("Upward at (" + i + "," + j + ")");
                        }
                        else if (board[i, j] == 1 && board[(i - 1), j] == 1 && board[(i - 2), j] == 1 && board[(i - 3), j] == 1)
                        {
                            xMatchList.Add("Upward at (" + i + "," + j + ")");
                        }
                    }
                }
            }

            //match print
            Console.WriteLine("O Match List:");
            for (int i = 0; i < oMatchList.Count; i++)
            {
                if (i > 0 && oMatchList[i].ToString()[0] != oMatchList[(i - 1)].ToString()[0])
                {
                    Console.WriteLine();
                }

                Console.WriteLine(oMatchList[i].ToString());
            }
            Console.WriteLine();
            
            Console.WriteLine("X Match List:");
            for (int i = 0; i < xMatchList.Count; i++)
            {
                if (i > 0 && xMatchList[i].ToString()[0] != xMatchList[(i - 1)].ToString()[0])
                {
                    Console.WriteLine();
                }

                Console.WriteLine(xMatchList[i].ToString());
            }

            Console.ReadLine();

        }
    }
}
